package com.fenghongzhang.day015;

import androidx.appcompat.app.AppCompatActivity;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class Main2Activity extends AppCompatActivity {
    private TextView text;
    private Button btn;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);


        text = (TextView) findViewById(R.id.text);
        btn = (Button) findViewById(R.id.btn);

        MyBroad myBroad = new MyBroad();
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction("com.feng");
        registerReceiver(myBroad,intentFilter);

    }

    public void down(View view) {
        Intent intent = new Intent(this, MyIntentService.class);
        startService(intent);
    }

    class MyBroad extends BroadcastReceiver{

        @Override
        public void onReceive(Context context, Intent intent) {
            Bundle extras = intent.getExtras();
            String json = extras.getString("json");
            text.setText(json);
        }
    }
}
